

<template>
  <div class="history-container">
    <div class="tabs">
      <ul class="tab-tilte">
        <li
          v-for="(itemTit, index) in times"
          :key="index"
          @mouseover="handleMouseOver(index)"
          @mouseout="handleMouseOut(index)"
          :class="{ active: cur == index }"
        >
          {{ itemTit }}
        </li>
      </ul>
      <div class="indicatorDots">
        <span
          :class="{ active: cur == i }"
          v-for="(v, i) in times"
          :key="i"
        ></span>
      </div>
      <div class="tab-content">
        <div v-for="(itemCon, index) in contents" :key="index" v-show="cur == index">
          <div v-for="(v, i) in itemCon" :key="i" class="content">
            {{ v }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'history',
    props: {
    height: {
      type: Number,
      default: 340
    },
    isSmooth: {
      type: Boolean,
      default: true
    },
    isArea: {
      type: Boolean,
      default: false
    },
    contents: {
       type: Array,
      default: () => []
    },
    times: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      timer: null,
  
      cur: 0 //默认选中第一个tab
    }
  },
  mounted() {
    this.getTimer()
  },
  methods: {
    getTimer() {
      this.timer = setInterval(() => {
        this.cur++
        if (this.cur == this.times.length) {
          this.cur = 0
        }
      }, 2000)
    },
    handleMouseOver(index) {
      this.cur = index
      clearInterval(this.timer)
    },
    handleMouseOut() {
      this.getTimer()
    }
  },
  beforeDestroy() {
    clearInterval(this.timer)
  }
}
</script>

<style lang="scss" scoped>
.history-container {
  margin: 0 10px;
      height: 300px;
  .tabs {
    display: flex;
    .tab-tilte {
      li {
        color: #fff;
        background-color: rgba(36, 196, 255, 0.5);
        text-align: center;
        cursor: pointer;
        width: 80px;
        height: 34px;
        line-height: 34px;
        margin-bottom: 15px;
        -webkit-border-radius: 5px;
        -ms-border-radius: 5px;
        -o-border-radius: 5px;
        -moz-border-radius: 5px;
        border-radius: 5px;
        &.active {
          background: linear-gradient(to right, #1b81bc, 20%, #24c4ff);
          color: #fff;
        }
      }
    }
    .indicatorDots {
      background-color: rgba(36, 196, 255, 0.5);
      width: 1px;
      height: 160px;
      margin: 20px 0 0 30px;
      span {
        display: block;
        height: 40px;
        margin-left: -6px;
        &:after {
          content: '';
          display: block;
          width: 10px;
          height: 10px;
          background: #ddd;
          -webkit-border-radius: 50%;
          -ms-border-radius: 50%;
          -o-border-radius: 50%;
          -moz-border-radius: 50%;
          border-radius: 50%;
          border: 2px solid #1b81bc;
        }
        &.active {
          &:after {
            background: #24c4ff;
            -webkit-box-shadow: 0 0 10px #1b81bc;
            box-shadow: 0 0 10px #1b81bc;
          }
        }
      }
    }
    .tab-content {
      display: flex;
      align-items: center;
      div {
        margin-left: 16px;
        color: #fff;
        .content {
          line-height: 24px;
          padding: 10px 0;
        }
      }
    }
  }
}
</style>
